/**
 * 
 */
package com.jm.utils.rule;

import com.jm.web.data.BaseDataEntity;
import com.jm.web.data.JMForm;

import groovy.lang.Binding;
import groovy.lang.Script;

/**
 * @author yanjie
 *
 */
public class BaseRuleEngine extends Script{
	protected JMForm form = null;
	
	protected BaseDataEntity data = null;
	
	public void init(JMForm form){
		this.form = form;
		Binding binding = new Binding();
		binding.setVariable("form", this.form);
		this.setBinding(binding);
	}
	
	public void init(JMForm form,BaseDataEntity data){
		this.form = form;
		this.data = data;
		Binding binding = new Binding();
		binding.setVariable("data", this.data);
		binding.setVariable("form", this.form);
		this.setBinding(binding);
	}
	
	public boolean Test(String strCode) throws Exception{
		boolean bRet = false;
		bRet = (Boolean)this.evaluate(strCode);
		return bRet;
	}
	
	public Object Eval(String strCode) throws Exception{
		Object bRet = null;
		bRet = this.evaluate(strCode);
		return bRet;
	}
	
	@Override
	public Object run() {
		return null;
	}
	
	public JMForm getForm() {
		return form;
	}

	public void setForm(JMForm form) {
		this.form = form;
	}

	public BaseDataEntity getData() {
		return data;
	}

	public void setData(BaseDataEntity data) {
		this.data = data;
	}
}
